#pragma once

// If an error occurred, display the HRESULT and exit.
#ifndef EXIT_ON_ERROR
#define EXIT_ON_ERROR(hr) if (FAILED(hr)) { wchar_t error[255]; swprintf_s(error, 254, L"HRESULT = %x", hr); MessageBox(0, error, L"Error, exiting.", 0); exit(1);    }
#endif

#include "resource.h"

/******************************************************************
*                                                                 *
*  AboutDlg                                                     *
*                                                                 *
******************************************************************/

class AboutDlg
{
public:
    AboutDlg();
    ~AboutDlg();
	void ShowAboutDlg(HWND hparent);

private:
    HRESULT CreateDeviceIndependentResources();
    HRESULT CreateDeviceResources();
	void	DiscardDeviceResources();
    HRESULT DrawText();

	static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

	void	OnPaint(HWND hwnd);
	BOOL	OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam);
	void	OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT code);
	void	OnHScroll(HWND hwnd, HWND hwndCtl, UINT code, int pos);
	void    OnClose(HWND hwnd);

	HRESULT Initialize(HWND hwnd);
	HRESULT DrawD2DContent();
	HRESULT EnumerateFonts(HWND comboBox);
	HRESULT SetFont(wchar_t *fontFamily);
	HRESULT SetFontSize(float size);
	HRESULT SetText(wchar_t *text);
	HRESULT SetBold(bool bold);
	HRESULT SetItalic(bool italic);
	HRESULT SetUnderline(bool underline);

	void	ReInitialize();
	
private:
    HWND hwnd_;

    float dpiScaleX_;
    float dpiScaleY_;

    // Direct2D
    ID2D1Factory			* pD2DFactory_;
    ID2D1HwndRenderTarget	* pRT_;
    ID2D1SolidColorBrush	* pBlackBrush_;

    // DirectWrite
    IDWriteFactory		* pDWriteFactory_;
    IDWriteTextFormat	* pTextFormat_;
    IDWriteTextLayout	* pTextLayout_;

    DWRITE_FONT_WEIGHT	weight_;
    DWRITE_FONT_STYLE	style_;
    BOOL				underline_;

	wchar_t * wszFontFamily_;
	float	fontSize_;

	wchar_t * wszText_;
	UINT32	cTextLength_;
};

